﻿using System.Collections.Generic;
using System.Web.Mvc;
using DoMain.IdentityRoles;
using DoMain.IdentityUsers;

namespace WebMvc.Controllers
{
    public class HomeController : BaseController
    {
        private IIdentityRoleRepository _roleRepo;
        private IIdentityUserRepository _userRepo;
        public HomeController(IIdentityRoleRepository roleRepo, IIdentityUserRepository userRepo) {
            _roleRepo = roleRepo;
            _userRepo = userRepo;
        }
        // GET: Home
        public ActionResult Index()
        {
            Response.Headers["Authorizatio"] = "诡异的jwt";
            if (User.Identity.IsAuthenticated)
            {
                Response.Write("你已经登陆。");
                
            }

          
            return View();
        }

        public JsonResult Aa() {

           

            
            return Json( new { });
        }
        [AllowAnonymous]
        public ActionResult Hub() 
        {
            return View();
        }

        [AllowAnonymous]
        public ActionResult Onlines()
        {
            return View();
        }

        [AllowAnonymous]
        public JsonResult GetOnlines()
        {
            var list = new List<OnlineItem>();
            foreach (var item in Core.CacheOnlineUsers.OnlineUsersDictionary)
            {
                list.Add( new OnlineItem{ ConnectionId=item.Key, Times=item.Value });
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        [AllowAnonymous]
        public ActionResult DemoPersistentConnection() {
            return View();
        }
    }
    public class OnlineItem {

        public string ConnectionId { get; set; }

        public string Times { get; set; }
    }
}